<?php
/**
 * Created by PhpStorm.
 * User: insgeek
 * Date: 2017/2/10
 * Time: 16:54
 */
namespace DesignPattern\Singleton;

class Mysql
{
    private $int;
    private static $con;

    private function __construct()
    {
        $this->int = mt_rand(1000, 9999);
        self::$con = mysqli_connect('localhost', 'root', '');
    }

    public static function getInstance()
    {
        if (!self::$con instanceof self) {
            self::$con = new self();
        }

        return self::$con;
    }

    private function __clone()
    {
        // TODO: Implement __clone() method.
    }

}

$mysql = Mysql::getInstance();
print_r($mysql);
$mysql1 = Mysql::getInstance();
print_r($mysql1);